home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTANKSRC.ZIP / NEWSHOP.C < prev    next >
C/C++ Source or Header  |  1995-03-07  |  20KB  |  812 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <graphics.h>
  4. #include <dtypes.h>
  5. #include <alloc.h>
  6. #include <string.h>
  7. #include <conio.h>
  8.  
  9. #include "loadpcx.h"
  10. #include "newshop.h"
  11. #include "ginput.h"
  12. #include <keybd.h>
  13.  
  14. #define _LOAD      1
  15. #define _SAVE      2
  16. #define _SHELL     3
  17. #define _LEAVE     4
  18. #define _NAME    101
  19. #define _CHASSIS 102
  20. #define _WEAPONS 103
  21. #define _EXTRAS  104
  22. #define _EDIT    200
  23. #define _PLAYERS 301
  24. #define _NOTEAM  302
  25. #define _TEAMA   303
  26. #define _TEAMB   304
  27. #define _GRASS   401
  28. #define _SWAMP   402
  29. #define _WOODS   403
  30. #define _VILLAGE 404
  31. #define _BATTLE  500
  32.  
  33. int chassis   = 1;
  34. int weapons[] = {0,0,0,0,0,0,0,0,0,0,0,0};
  35. int extras[]  = {0,0,0,0,0,0,0,0,0,0,0,0};
  36.  
  37. PSTR menu0[] = {"FILE", "CONFIG", "EDIT", "TEAMS", "TERRAIN", "BATTLE", ""};
  38.  
  39. PSTR menu1[] = {"LOAD",
  40.                 "SAVE",
  41.                 "SHELL",
  42.                 "EXIT",""};
  43.  
  44. PSTR menu2[] = {"NAME",
  45.                 "CHASSIS",
  46.                 "WEAPONS",
  47.                 "EXTRA'S",""};
  48.  
  49. PSTR menu4[] = {"PLAYERS",
  50.                 "NO TEAM",
  51.                 "TEAM A",
  52.                 "TEAM B",""};
  53.  
  54. PSTR menu5[] = {"GRASS",
  55.                 "SWAMP",
  56.                 "WOODS",
  57.                 "VILLAGE",""};
  58.  
  59. PSTR menu6[] = {"MACHINE 16mm",
  60.                 "MACHINE  8mm",
  61.                 "LASER",
  62.                 "CANNON",
  63.                 "ROCKET",
  64.                 "MINE",
  65.                 "RADIO MINE",""};
  66.  
  67. PSTR smenu6[]= {"MACH16",
  68.                 "MACH 8",
  69.                 "LASER ",
  70.                 "CANNON",
  71.                 "ROCKET",
  72.                 "MINE  ",
  73.                 "R MINE",""};
  74.  
  75. PSTR menu7[] = {"LIGHTWEIGHT",
  76.                 "REGULATION",
  77.                 "HEAVYWEIGHT",""};
  78.  
  79. PSTR frame[] = {"LIGHT",
  80.                   "REG.",
  81.                   "HEAVY",""};
  82.  
  83. PSTR menu8[] = {"RADAR",
  84.                 "SCANNER",
  85.                 "SCOPE",
  86.                 "RADAR JAMMER",
  87.                 "RADIO TX",
  88.                 "RADIO RX",
  89.                 "MINE DETECT",
  90.                 "MINE SCOOP",""};
  91.  
  92. PSTR smenu8[]= {"RADAR ",
  93.                 "SCAN  ",
  94.                 "SCOPE ",
  95.                 "JAMMER",
  96.                 "TX    ",
  97.                 "RX    ",
  98.                 "DETECT",
  99.                 "SCOOP ",""};
  100.  
  101. PSTR menu9[] = {"1          N",
  102.                 "2          N",
  103.                 "3          N",
  104.                 "4          N",
  105.                 "5          N",
  106.                 "6          N",
  107.                 "7          N",
  108.                 "8          N",
  109.                 "9          N",
  110.                 "0          N",""};
  111.  
  112. TSS  tnk;
  113.  
  114. PSTR wind;
  115.  
  116. BOOL fileerr = FALSE;
  117.  
  118. BOOL saveit = TRUE;
  119. int  select;
  120. BOOL picked;
  121. int  lastpick = 0;
  122. char bbuf[20];
  123. int terrain = 0;
  124.  
  125. /*-------------------------------------
  126.  * Function : void main(void)
  127.  * Purpose  : Main calling module for NEWSHOP.C
  128.  * Date     : 02/19/1989 17:10:26
  129.  */
  130. void main(void)
  131. {
  132. char buf[80];
  133.  
  134.     strcpy(bbuf,"NONAME");
  135.  
  136.     clrscr();
  137.     cprintf("RoboTank was written (back in '89) by:\r\n");
  138.     cprintf("Alexander Walsh (sandy@cs.mun.ca)\r\n\r\n");
  139.     cprintf("Please distribute freely, email any comments you may have.\r\n");
  140.     cprintf("Note: I will not be doing upgrades to this program\r\n");
  141.     cprintf("      (it was a nice idea at the time)\r\n");
  142.     while (!kbhit())
  143.     ;
  144.     (void) getch();
  145.  
  146.     register_bgi();
  147.  
  148.     set_screen_mode(4);
  149.  
  150.     Load_CGA_PCX("X4972.X90");
  151.     while (!kbhit())
  152.     ;
  153.     (void) getch();
  154.  
  155. #if 0
  156.     Load_CGA_PCX("YYZ01.270");
  157.     while (!kbhit())
  158.     ;
  159.     (void) getch();
  160. #endif
  161.  
  162.     Load_CGA_PCX("Z44YX.A20");
  163.  
  164.     select=0;
  165.  
  166.     while (select!=_LEAVE) {
  167.  
  168.         picked=FALSE;
  169.         operate_topmenu(menu0);
  170.         picked=FALSE;
  171.  
  172.         switch(select) {
  173.             case _SAVE   : to_TSS(&tnk);
  174.                            save_TSS(&tnk,bbuf);
  175.                            break;
  176.  
  177.             case _LOAD   : get_a_tank_name(bbuf);
  178.                            fileerr=FALSE;
  179.                            load_TSS(&tnk,bbuf);
  180.                            if (!fileerr) {
  181.                                explode_TSS(&tnk);
  182.                                display_new_TSS();
  183.                            }
  184.                            break;
  185.  
  186.             case _EDIT   : set_screen_mode(3);
  187.                            strcpy(buf,"ms.com ");
  188.                            strcat(buf,bbuf);
  189.                            strcat(buf,".txt");
  190.  
  191.                            system(buf);
  192.                            set_screen_mode(4);
  193.                            Load_CGA_PCX("Z44YX.A20");
  194.                            display_new_TSS();
  195.                            break;
  196.  
  197.             case _WEAPONS: use_large_picklist(_WEAPONS,menu6);
  198.                            break;
  199.  
  200.             case _CHASSIS: use_large_picklist(_CHASSIS,menu7);
  201.                            break;
  202.  
  203.             case _EXTRAS : use_large_picklist(_EXTRAS ,menu8);
  204.                            break;
  205.  
  206.             case _PLAYERS: use_large_picklist(_PLAYERS,menu9);
  207.                            break;
  208.  
  209.             case _NOTEAM : use_large_picklist(_NOTEAM ,menu9);
  210.                            break;
  211.  
  212.             case _TEAMA  : use_large_picklist(_TEAMA  ,menu9);
  213.                            break;
  214.  
  215.             case _TEAMB  : use_large_picklist(_TEAMB  ,menu9);
  216.                            break;
  217.  
  218.             case _NAME   : moveto(170,40); strcpy(bbuf,ggetline(8,bbuf));
  219.                            break;
  220.  
  221.             case _GRASS  :
  222.             case _SWAMP  :
  223.             case _WOODS  :
  224.             case _VILLAGE: setcolor(CGA_WHITE);
  225.                            bar(30,170,100,177);
  226.                            setcolor(BLACK);
  227.                            moveto(30,170);
  228.                            outtext(menu5[select-_GRASS]);
  229.                            terrain=select-_GRASS;
  230.                            break;
  231.  
  232.             case _BATTLE : prepare_for_battle();
  233.                            break;
  234.         }
  235.     }
  236.  
  237.     closegraph();
  238. } /* void main(void) */
  239.  
  240. /*-------------------------------------
  241.  * Function : void use_large_picklist(int table, PSTR list[])
  242.  * Purpose  : Operate the large picklist
  243.  * Date     : 02/20/1989 21:13:05
  244.  */
  245. void use_large_picklist(int table, PSTR list[])
  246. {
  247. char name[10];
  248. int a;
  249.  
  250.     select=1;
  251.     lastpick=0;
  252.  
  253.     while (select!=0) {
  254.  
  255.        picked=saveit=FALSE;
  256.        select=0;
  257.        operate_pulldown(26,50,list);
  258.        saveit=TRUE;
  259.  
  260.        switch(table) {
  261.  
  262.            case _WEAPONS: display_pick(170,select,weapons,smenu6);
  263.                           break;
  264.  
  265.            case _EXTRAS : display_pick(245,select,extras ,smenu8);
  266.                           break;
  267.  
  268.            case _CHASSIS: if (select>0) {
  269.                               setcolor(CGA_WHITE);
  270.                               bar(250,40,300,50);
  271.                               setcolor(BLACK);
  272.                               moveto(250,40);
  273.                               outtext(frame[select-1]);
  274.                               chassis=select-1;
  275.                           }
  276.                           break;
  277.  
  278.            case _TEAMA  : if (select>0)
  279.                              pickteam(select-1,'A');
  280.                           break;
  281.  
  282.            case _TEAMB  : if (select>0)
  283.                              pickteam(select-1,'B');
  284.                           break;
  285.  
  286.            case _NOTEAM : if (select>0)
  287.                              pickteam(select-1,'N');
  288.                           break;
  289.  
  290.            case _PLAYERS: if (select>0) {
  291.  
  292.                              strncpy(name,menu9[select-1]+2,8);
  293.                              name[8]=NULL;
  294.  
  295.                              setcolor(CGA_WHITE);
  296.                              moveto(30,54+((select-1)*10));
  297.                              outtext(menu9[select-1]);
  298.  
  299.                              get_a_tank_name(name);
  300.  
  301.                              for (a=0; a<8; a++)
  302.                                  *(menu9[select-1]+2+a)=' ';
  303.  
  304.                              for (a=0; a<8 && name[a]!=NULL; a++)
  305.                                  *(menu9[select-1]+2+a)=name[a];
  306.  
  307.                              setcolor(CGA_RED);
  308.                              moveto(30,54+((select-1)*10));
  309.                              outtext(menu9[select-1]);
  310.  
  311.                           }
  312.                           break;
  313.        }
  314.     }
  315.  
  316.     setcolor(CGA_WHITE);
  317.     bar(26,52,130,160);
  318. } /* void use_large_picklist(int table, PSTR list[]) */
  319.  
  320. /*-------------------------------------
  321.  * Function : void pickteam(int pick, char new)
  322.  * Purpose  : Pick a new team and display results
  323.  * Date     : 02/26/1989 12:37:30
  324.  */
  325. void pickteam(int pick, char new)
  326. {
  327.     setcolor(CGA_WHITE);
  328.     moveto(30,54+(pick*10));
  329.     outtext(menu9[pick]);
  330.  
  331.     *(menu9[pick]+11)=new;
  332.  
  333.     setcolor(BLACK);
  334.     moveto(30,54+(pick*10));
  335.     outtext(menu9[pick]);
  336.  
  337. } /* void pickteam(int pick, char new) */
  338.  
  339. /*-------------------------------------
  340.  * Function : void display_pick(int x, int pick, int set[], PSTR list[])
  341.  * Purpose  : Display the choice picked
  342.  * Date     : 02/20/1989 21:45:24
  343.  */
  344. void display_pick(int x, int pick, int set[], PSTR list[])
  345. {
  346. int y;
  347.  
  348.     pick--;
  349.  
  350.     y=54+pick*10;
  351.     moveto(x,y);
  352.     setcolor(set[pick] ? CGA_WHITE : BLACK);
  353.     outtext(list[pick]);
  354.     set[pick] = set[pick] ? FALSE : TRUE;
  355.  
  356. } /* void display_pick(int x, int pick, int set[], PSTR list[]) */
  357.  
  358. /*-------------------------------------
  359.  * Function : void operate_topmenu(PSTR op[])
  360.  * Purpose  : Operate the top portion of a pulldown menu system
  361.  * Date     : 02/19/1989 17:32:33
  362.  */
  363. void operate_topmenu(PSTR op[])
  364. {
  365. int a, ni, ch;
  366. int x[20];
  367.  
  368.     ni=0; select=0; picked=FALSE;
  369.  
  370.     moveto(10,10); setcolor(BLACK);
  371.  
  372.     while (*op[ni]) {
  373.         x[ni]=getx();
  374.         outtext(op[ni++]);
  375.         outtext(" ");
  376.     }
  377.  
  378.     ch=' '; a=0;
  379.  
  380.     while (ch!=ESC && !picked) {
  381.  
  382.         select=a*100;
  383.  
  384.         light_word(x[a],10,op[a]);
  385.  
  386.         while(!kbhit())
  387.             ;
  388.  
  389.         ch=getkey();
  390.  
  391.         if (ch==LF_ARR || ch==RT_ARR || ch==ESC || ch==DN_ARR || ch==CR) {
  392.  
  393.             if (ch!=DN_ARR)
  394.                 unlight_word(x[a],10,op[a]);
  395.  
  396.             if (ch==LF_ARR && a>0)
  397.                 a--;
  398.             if (ch==RT_ARR && a<ni-1)
  399.                 a++;
  400.             if (ch==DN_ARR || ch==CR) {
  401.  
  402.                 lastpick=0;
  403.  
  404.                 if (a==0)
  405.                     operate_pulldown(x[a],20,menu1);
  406.  
  407.                 if (a==1)
  408.                     operate_pulldown(x[a],20,menu2);
  409.  
  410.                 if (a==2 && ch==CR)
  411.                     picked=TRUE;
  412.                 if (a==3)
  413.                     operate_pulldown(x[a],20,menu4);
  414.  
  415.                 if (a==4)
  416.                     operate_pulldown(x[a],20,menu5);
  417.  
  418.                 if (a==5 && ch==CR)
  419.                     picked=TRUE;
  420.             }
  421.         }
  422.     }
  423.     unlight_word(x[a],10,op[a]);
  424.  
  425. } /* void operate_topmenu(PSTR op[]) */
  426.  
  427. /*-------------------------------------
  428.  * Function : void operate_pulldown(int x, int y, PSTR op1[])
  429.  * Purpose  : Operate pulldown menu at (x,y)
  430.  * Date     : 02/19/1989 18:20:12
  431.  */
  432. void operate_pulldown(int x, int y, PSTR op1[])
  433. {
  434. int a,ni, yc;
  435. int yy[20];
  436. int ch;
  437. int buf[1100];
  438.  
  439.     if (saveit) {
  440.         getimage(x,y,x+65,y+45,buf);
  441.         setcolor(CGA_WHITE);
  442.         bar(x,y,x+65,y+45);
  443.         setcolor(BLACK);
  444.         rectangle(x,y,x+65,y+45);
  445.     }
  446.  
  447.     ni=0; yc=y+4; x+=4;
  448.  
  449.     setcolor(BLACK);
  450.     while (*op1[ni]) {
  451.         moveto(x,yc);
  452.         yy[ni]=yc;
  453.         outtext(op1[ni++]);
  454.         yc+=10;
  455.     }
  456.  
  457.     a=lastpick; ch=' ';
  458.  
  459.     while (ch!=ESC && !picked) {
  460.         light_word(x,yy[a],op1[a]);
  461.  
  462.         while (!kbhit())
  463.             ;
  464.  
  465.         ch=getkey();
  466.  
  467.         if (ch==UP_ARR || ch==DN_ARR || ch==CR) {
  468.  
  469.             unlight_word(x,yy[a],op1[a]);
  470.  
  471.             if (ch==DN_ARR && a<ni-1)
  472.                 a++;
  473.  
  474.             if (ch==CR)
  475.                 picked=TRUE, select+=(a+1);
  476.  
  477.             if (ch==UP_ARR) {
  478.                 if (a==0 && saveit)
  479.                     ch=ESC;
  480.                 else if (a>0)
  481.                     a--;
  482.             }
  483.         }
  484.     }
  485.     if (saveit)
  486.         putimage(x-4,y,buf,COPY_PUT);
  487.  
  488.     lastpick=a;
  489.  
  490. } /* void operate_pulldown(int x, int y, PSTR op1[]) */
  491.  
  492. /*-------------------------------------
  493.  * Function : void light_word(int x, int y, char *s)
  494.  * Purpose  : Highlight word at (x,y)
  495.  * Date     : 02/19/1989 18:02:42
  496.  */
  497. void light_word(int x, int y, char *s)
  498. {
  499.     setcolor(BLACK);
  500.     rectangle(x-2,y-2,x+textwidth(s),y+8);
  501.     moveto(x,y);
  502.     setcolor(CGA_RED);
  503.     outtext(s);
  504. } /* void light_word(int x, int y, char *s) */
  505.  
  506. /*-------------------------------------
  507.  * Function : void unlight_word(int x, int y, char *s)
  508.  * Purpose  : Un-highlight word at (x,y)
  509.  * Date     : 02/19/1989 18:06:07
  510.  */
  511. void unlight_word(int x, int y, char *s)
  512. {
  513.     setcolor(CGA_WHITE);
  514.     rectangle(x-2,y-2,x+textwidth(s),y+8);
  515.     moveto(x,y);
  516.     setcolor(BLACK);
  517.     outtext(s);
  518. } /* void unlight_word(int x, int y, char *s) */
  519.  
  520. /*-------------------------------------
  521.  * Function : void register_bgi(void)
  522.  * Purpose  : Register the BGI driver for CGA
  523.  * Date     : 02/19/1989 17:16:18
  524.  */
  525. void register_bgi(void)
  526. {
  527. int gm, gd;
  528.  
  529.     if (registerfarbgidriver(CGA_driver_far) < 0) {
  530.         printf("Color graphics adapter required for this program\n");
  531.         exit(1);
  532.     };
  533.  
  534.     gm=CGAC1;
  535.     gd=CGA;
  536.  
  537.     initgraph(&gd,&gm,"");
  538.  
  539.     if (graphresult()<0) {
  540.         printf("Graphics driver initilization error, CGA required\n");
  541.         exit(1);
  542.     }
  543. } /* void register_bgi(void) */
  544.  
  545. /*-------------------------------------
  546.  * Function : void open_wind(void)
  547.  * Purpose  : Open dialog box window
  548.  * Date     : 02/26/1989 12:53:21
  549.  */
  550. void open_wind(void)
  551. {
  552. int size;
  553.  
  554.    size=imagesize(70,70,250,160);
  555.  
  556.    if ((wind=malloc(size))==NULL) {
  557.        printf("Cannot Malloc()\n");
  558.        exit(1); /* Temp error */
  559.    }
  560.  
  561.    getimage(70,70,250,160,wind);
  562.  
  563.    setfillstyle(CLOSE_DOT_FILL,CGA_RED);
  564.    bar(70,70,250,160);
  565.    setfillstyle(SOLID_FILL,CGA_WHITE);
  566.    bar(80,80,240,150);
  567.    setcolor(BLACK);
  568.    rectangle(70,70,250,160);
  569.    rectangle(80,80,240,150);
  570.  
  571. } /* void open_wind(void) */
  572.  
  573. /*-------------------------------------
  574.  * Function : void get_a_tank_name(PSTR s)
  575.  * Purpose  : Get a tank name in string S
  576.  * Date     : 02/26/1989 13:07:47
  577.  */
  578. void get_a_tank_name(PSTR s)
  579. {
  580.    open_wind();
  581.  
  582.    moveto(90,90); outtext("ENTER TANK NAME:");
  583.    moveto(100,110);
  584.  
  585.    ggetline(8,s);
  586.  
  587.    close_wind();
  588. } /* void get_a_tank_name(PSTR s) */
  589.  
  590. /*-------------------------------------
  591.  * Function : void close_wind(void)
  592.  * Purpose  : Close dialog box window
  593.  * Date     : 02/26/1989 12:57:05
  594.  */
  595. void close_wind(void)
  596. {
  597.     putimage(70,70,wind,COPY_PUT);
  598.     free(wind);
  599. } /* void close_wind(void) */
  600.  
  601. /*-------------------------------------
  602.  * Function : void to_TSS(p_TSS t)
  603.  * Purpose  : Copy in-memory TSS to actual TSS structure
  604.  * Date     : 02/26/1989 16:02:30
  605.  */
  606. void to_TSS(p_TSS t)
  607. {
  608. int a;
  609.  
  610.    t->t_chassis=chassis;
  611.  
  612.    for (a=0; a<10; a++) {
  613.        t->t_weapons[a]=weapons[a];
  614.        t->t_extras[a] =extras[a];
  615.    }
  616.    strcpy(t->name,"");
  617.  
  618. } /* void to_TSS(p_TSS t) */
  619.  
  620. /*-------------------------------------
  621.  * Function : void explode_TSS(p_TSS t)
  622.  * Purpose  : Explode a TSS into it's component parts into memory
  623.  * Date     : 02/26/1989 16:13:08
  624.  */
  625. void explode_TSS(p_TSS t)
  626. {
  627. int a;
  628.  
  629.    chassis=t->t_chassis;
  630.  
  631.    for (a=0; a<10; a++) {
  632.        weapons[a]=t->t_weapons[a];
  633.        extras[a] =t->t_extras[a];
  634.    }
  635.  
  636. } /* void explode_TSS(p_TSS t) */
  637.  
  638. /*-------------------------------------
  639.  * Function : void save_TSS(p_TSS t, PSTR fn)
  640.  * Purpose  : Save tank T to filename FN
  641.  * Date     : 02/26/1989 16:06:48
  642.  */
  643. void save_TSS(p_TSS t, PSTR fn)
  644. {
  645. FILE *fp;
  646.  
  647.     if (*fn==NULL)
  648.         return;
  649.  
  650.     if ((fp=fopen(fn,"wb"))==NULL) {
  651.         printf("Cannot create file \n");  /* temp */
  652.         exit(1);
  653.     }
  654.     fwrite(t,sizeof(TSS),1,fp);
  655.  
  656.     fclose(fp);
  657. } /* void save_TSS(p_TSS t, PSTR fn) */
  658.  
  659. /*-------------------------------------
  660.  * Function : void load_TSS(p_TSS t, PSTR fn)
  661.  * Purpose  : Load in a TSS structure from disk
  662.  * Date     : 02/26/1989 16:12:03
  663.  */
  664. void load_TSS(p_TSS t, PSTR fn)
  665. {
  666. FILE *fp;
  667.  
  668.     if (*fn==NULL)
  669.         return;
  670.  
  671.     if ((fp=fopen(fn,"rb"))==NULL) {
  672.         show_error("CANNOT OPEN FILE");
  673.         fileerr=TRUE;
  674.     } else {
  675.  
  676.         fread(t,sizeof(TSS),1,fp);
  677.  
  678.         fclose(fp);
  679.    }
  680. } /* void load_TSS(p_TSS t, PSTR fn) */
  681.  
  682. /*-------------------------------------
  683.  * Function : void display_new_TSS(void)
  684.  * Purpose  : Redraw screen with newly loaded tank specs
  685.  * Date     : 02/26/1989 16:22:52
  686.  */
  687. void display_new_TSS(void)
  688. {
  689. int a;
  690.  
  691.     /* Clear picklist */
  692.  
  693.     setcolor(CGA_WHITE);
  694.     bar(26,52,130,160);
  695.  
  696.     bar(170,54,220,150); /* weapons list */
  697.     bar(245,54,300,150); /* extras list  */
  698.  
  699.     bar(170,40,300,50);  /* Tank name line */
  700.  
  701.     setcolor(BLACK);
  702.  
  703.     for (a=0; a<10; a++) {
  704.         if (weapons[a]) {
  705.             moveto(170, 54+a*10);
  706.             outtext(smenu6[a]);
  707.         }
  708.         if (extras[a]) {
  709.             moveto(245, 54+a*10);
  710.             outtext(smenu8[a]);
  711.         }
  712.     }
  713.  
  714.     moveto(170,40); outtext(bbuf);
  715.     moveto(250,40); outtext(frame[chassis]);
  716. } /* void display_new_TSS(void) */
  717.  
  718. /*-------------------------------------
  719.  * Function : void show_error(char *s)
  720.  * Purpose  : Display an error in window
  721.  * Date     : 02/26/1989 16:45:03
  722.  */
  723. void show_error(char *s)
  724. {
  725.     open_wind();
  726.     moveto(85,100);
  727.  
  728.     outtext(s);
  729.     moveto(110,120);
  730.  
  731.     outtext("PRESS ENTER ");
  732.     ggetline(1,"   ");
  733.  
  734.     close_wind();
  735.  
  736. } /* void show_error(char *s) */
  737.  
  738. /*-------------------------------------
  739.  * Function : void prepare_for_battle(void)
  740.  * Purpose  : Get ready to call shop.exe for the big fight
  741.  * Date     : 02/26/1989 16:37:15
  742.  */
  743. void prepare_for_battle(void)
  744. {
  745. int  a;
  746. int nc;
  747. BOOL any;
  748. TSS player;
  749. char nm[20];
  750. char buf[50];
  751. FILE *fp;
  752. BOOL good=TRUE;
  753.  
  754.     if ((fp=fopen("BATTLE.DAT","wb"))==NULL) {
  755.         show_error("DISK ERROR");
  756.         return;
  757.     }
  758.  
  759.     any=FALSE;
  760.     nc=0;
  761.  
  762.     for (a=0; a<10; a++)
  763.         if (*(menu9[a]+2) != ' ')
  764.             any=TRUE, nc++;
  765.  
  766.     if (!any) {
  767.         show_error("NO PLAYERS");
  768.         good=FALSE;
  769.     } else {
  770.         fileerr=FALSE;
  771.  
  772.         putw(nc,fp);       /* Write out the number of contestants */
  773.         putw(terrain,fp);  /* Where are we fighting ??? */
  774.  
  775.         for (a=0; a<10 && !fileerr; a++)
  776.             if (*(menu9[a]+2) != ' ') {
  777.  
  778.                 strncpy(nm, menu9[a]+2, 8);
  779.                 nm[8]=NULL;
  780.  
  781.                 fileerr=FALSE;
  782.                 load_TSS(&player,nm);
  783.  
  784.                 if (fileerr) {
  785.                     sprintf(buf,"BAD NAME \"%s\"",nm);
  786.                     show_error(buf);
  787.                     good=FALSE;
  788.                 } else {
  789.  
  790.                     switch (*(menu9[a]+11)) {
  791.                         case 'N' : player.team=0; break;
  792.                         case 'A' : player.team=1; break;
  793.                         case 'B' : player.team=2; break;
  794.                     }
  795.  
  796.             strcpy(player.name,nm);    /* Save tank's name */
  797.  
  798.                     fwrite(&player,sizeof(TSS),1,fp);  /* Write out player */
  799.                 }
  800.             }
  801.     }
  802.  
  803.     fclose(fp);
  804.  
  805.     if (good) {
  806.         set_screen_mode(3);
  807.         system("host.exe");
  808.         set_screen_mode(4);
  809.         Load_CGA_PCX("Z44YX.A20");
  810.         display_new_TSS();
  811.     }
  812. } /* void prepare_for_battle(void) */